<?php

namespace app\mobile\controller;

class Bbs extends Base
{

    public function index($navid=null)
    {
        $list = model('bbs')->where($this->datas)->paginate();
        $this->assign('list',$list);
        return $this->fetch($this->template . $this->request->controller().'.html');
    }



    public function detailed($id)
    {
        //显示内容
        $model = $this->request->controller();

            $data = model($model)->where($this->datas)->find($id);
            model($model)->where('id',$id)->setInc('scon',1);
        if(!$data){
            $this->redirect($this->request->domain());
        }

        $list=model('bbsmass')->where($this->datas)->where('fid',$id)->limit(5)->select();
        //更多页面
        !empty($data['cid']) ? $datas['cid'] = $data['cid'] : '';
        $datas['status'] = '1';
        $datas['lang'] = cookie('think_var');
        $next = model($model)->getnext($id, $datas);
        $this->assign([
            'data'=> $data,
            'next'=> $next,
            'list'=> $list,
            ]);
        return $this->fetch($this->template . $this->request->controller(). 'detailed.html');
    }

    public function savemass(){
        $aa = session('User', '', 'User');

        if(empty($aa->id)){
            return ajax_info('请登录再留言！');

        }
        if($this->request->isPost()){
            $post = $this->request->param();
            $data['fid']=$post['id'];
            $data['status']=0;
            $data['create_time']=time();
            $data['username']=$aa->name;
            $data['uid']=$aa->id;
            $data['center']=$post['center'];
            $list=model('bbsmass')->save($data);
            if($list){
                return ajax_info('留言成功等待审核','u');
            }else{
                return ajax_info('重复留言');

            }
        }
    }

    public function bbsread($id){
        $data = model('Bbs')->where($this->datas)->find($id);

        $list = model('bbsmass')->where($this->datas)->where('fid',$id)->paginate();
        $this->assign([
            'data'=>$data,
            'list'=>$list,
        ]);
        return $this->fetch($this->template . 'bbsread.html');
    }

}

